package com.wywah.common.domain;

import com.wywah.common.http.HttpStatus;

public class R<T> {

    private int code;
    private String msg;
    private T data;

    public static <T> R<T> ok(HttpStatus status, T data) {
        R<T> r = new R<>();
        r.setCode(status.code).setMsg(status.message).setData(data);
        return r;
    }

    public static <T> R<T> ok(T data) {
        return ok(HttpStatus.OK, data);
    }

    public static R<Object> error(HttpStatus status, String msg) {
        R<Object> r = new R<>();
        r.setCode(status.code).setMsg(msg);
        return r;
    }

    public static R<Object> error(int code, String msg) {
        R<Object> r = new R<>();
        r.setCode(code).setMsg(msg);
        return r;
    }

    public static R<Object> error(String msg) {
        return error(HttpStatus.FAIL, msg);
    }

    public int getCode() {
        return code;
    }

    public R<T> setCode(int code) {
        this.code = code;
        return this;
    }

    public String getMsg() {
        return msg;
    }

    public R<T> setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public T getData() {
        return data;
    }

    public R<T> setData(T data) {
        this.data = data;
        return this;
    }
}
